/**
	Copyright (c) 2010 ATTi 
	All rights reserved.
	Author: Michael Shu
	Date: 4/16/2011
*/

trigger CaseBusinessDayAged on Case (after insert, after update) {
	if(trigger.isAfter){
		if(trigger.isInsert){
			list<Case> cases_to_insertCC = new list<Case>();
			for(Case c : trigger.new){
				if(!c.IsClosed){
					cases_to_insertCC.add(c);
				}
			}
			if(!cases_to_insertCC.isEmpty()){
				CaseBusinessDayHelper.createCaseCyles(cases_to_insertCC);
			}
		}else if(trigger.isUpdate){
			set<ID> casesIds = new set<ID>();
			for(Case c : trigger.new){
				casesIds.add(c.Id);
			}
			if(!casesIds.isEmpty()){
				CaseBusinessDayHelper.createAndupdateCaseCyles(casesIds);
			}
		}
	}
}